﻿Imports System
Imports System.Diagnostics.CodeAnalysis
Imports System.Reflection

Namespace System.Workflow.Activities.Rules
    Friend Class EnumHelper
        ' Methods
        <SuppressMessage("Microsoft.Performance", "CA1803:AvoidCostlyCallsWherePossible")> _
        Public Shared Function GetUnderlyingType(ByVal type As Type) As Type
            Dim type2 As Type = GetType(Integer)
            If type.GetType.FullName.Equals("System.Workflow.ComponentModel.Compiler.DesignTimeType", StringComparison.Ordinal) Then
                Dim method As MethodInfo = type.GetType.GetMethod("GetEnumType")
                If (Not method Is Nothing) Then
                    Dim type3 As Type = [TryCast](method.Invoke(type, New Object(0  - 1) {}),Type)
                    type2 = If((Not type3 Is Nothing), type3, type2)
                End If
                Return type2
            End If
            Return Enum.GetUnderlyingType(type)
        End Function

    End Class
End Namespace

